package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class UpdateOperation implements IOperation{

    @Override
    public void work(BookList bookList) {
        System.out.println("修改图书");
        System.out.println("请输入要修改的书名:");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        for (int i = 0; i < bookList.getNumber(); i++) {
            if (name.equals(bookList.getBook(i).getName())) {
                System.out.println("已找到!");
                System.out.println("修改后的书名:");
                String name2 = scanner.nextLine();
                System.out.println("修改后的作者:");
                String author = scanner.nextLine();
                System.out.println("修改后的价格:");
                int price = scanner.nextInt();
                System.out.println("修改后的类型:");
                String none = scanner.nextLine();
                String type = scanner.nextLine();

                Book book = new Book(name2,author,price,type);
                bookList.setBook(book,i);
                System.out.println("修改成功!");
                return;
            }
        }
    }
}
